using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DamageIndicatorManager:MonoBehaviour {
	void Start() {
		indicatorPrefab=Resources.Load<GameObject>("DamageIndicator");
		SubscribeEvents();
	}
	void Update() {

	}
	void OnDestroy() {
		UnsubscribeEvents();
	}

	GameObject indicatorPrefab;

	void SubscribeEvents() {
		Mob.Damaged+=DamagedEventHandler;
	}
	void UnsubscribeEvents() {
		Mob.Damaged-=DamagedEventHandler;
	}

	void DamagedEventHandler(object sender,DamageEventArgs e) {
		GameObject indicatorObject = Instantiate(indicatorPrefab,transform);
		DamageIndicator indicator = indicatorObject.GetComponent<DamageIndicator>();
		indicator.Init(e.stat);
	}
}